package cloud.keveri.springboot.starter.gateway.plugin.call;

import cloud.keveri.gateway.dto.RpcConfig;
import cloud.keveri.gateway.plugin.api.KeveriPlugin;
import cloud.keveri.gateway.plugin.call.RemoteCallPlugin;
import cloud.keveri.gateway.plugin.call.proxy.DubboProxyService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static cloud.keveri.gateway.plugin.call.def.Const.Rpc_Config_Prefix;

/**
 * <p>
 * 作者：沈自在
 **/
@Configuration
@ConditionalOnClass(RemoteCallPlugin.class)
public class GatewayPluginCallAutoConfiguration {

    @Bean
    @ConfigurationProperties(prefix = Rpc_Config_Prefix)
    public RpcConfig rpcConfig(){
        return new RpcConfig();
    }

    /**
     * TODO 需要编排配置 init
     */
    @Bean
    public KeveriPlugin remoteCallPlugin(final RpcConfig rpcConfig) {
        DubboProxyService dubboProxyService = new DubboProxyService();
        dubboProxyService.init(rpcConfig);
        return new RemoteCallPlugin(dubboProxyService);
    }
}
